<link rel="stylesheet" href="/resource/layadmin/assets/css/login.css?v=315">
<div class="login-wrapper layui-anim layui-anim-scale layui-hide">
    <form class="layui-form">
        <h2>管理员登录</h2>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-username"></i>
            <input class="layui-input" name="username" placeholder="请输入登录账号" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input class="layui-input" name="password" placeholder="请输入登录密码" type="password"
                   lay-verType="tips" lay-verify="required" required autocomplete="off"/>
        </div>
        <div class="layui-form-item layui-input-icon-group login-captcha-group">
            <i class="layui-icon layui-icon-auz"></i>
            <input name="captcha" type="text" placeholder="请输入验证码" class="layui-input" id="LAY-user-captcha"
                   autocomplete="off" lay-verType="tips" lay-verify="required" required/>
            <img class="login-captcha" src="captcha?captcha_id={{.captchaId}}" alt="">
        </div>
        <div class="layui-form-item">
            <!--            <input type="checkbox" name="remember" title="记住密码" lay-skin="primary" checked>-->
            <!--            <a href="reg.html" class="layui-link pull-right">注册账号</a>-->
        </div>
        <div class="layui-form-item">
            <button lay-filter="login-submit" id="login-submit" type="button" class="layui-btn layui-btn-fluid"
                    lay-submit>登 录
            </button>
        </div>
    </form>
</div>
<div class="login-copyright">{{.Description}}</div>
<script type="text/javascript">
    layui.use(['layer', 'form', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;

        /** * 是否为mac系统（包含iphone手机） * */
        var isMac = function () {
            return /macintosh|mac os x/i.test(navigator.userAgent);
        }();

        /** * 是否为windows系统 * */
        var isWindows = function () {
            return /windows|win32/i.test(navigator.userAgent);
        }();

        $('.login-wrapper').removeClass('layui-hide');

        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            var params = obj.field;
            // 记录当前登录的设备浏览器信息
            params['login_device'] = isMac ? 'Mac' : (isWindows ? 'Windows' : '未知设备')
            params['login_browser'] = myBrowser();
            layer.load(2, {shade: false});
            admin.req('/admin/login', params, function (res) {
                layer.closeAll('loading');
                if (res.code === 0) {
                    admin.putTempData("userAuthList", res.data.auth_list, true)
                    layer.msg('登录成功', {icon: 1, time: 1500}, function () {
                        location.href = '/admin/'; //后台主页
                    });
                } else {
                    layer.msg(res.msg, {icon: 2});
                    $(".login-captcha").attr("src", "captcha?v=" + Math.random());
                }
            }, 'post');
            return false;
        });

        // 图形验证码
        $(".login-captcha").on("click", function () {
            $(".login-captcha").attr("src", "/captcha?v=" + Math.random());
        });

        $('#LAY-user-captcha').on('keydown', function (event) {
            if (event.keyCode == 13) {
                $("#login-submit").trigger("click");
                return false
            }
        });

        $('#beian').click(function () {
            window.open('https://beian.miit.gov.cn/')
        })
    });

    //判断是什么浏览器（无版本控制）
    function myBrowser() {
        var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
        var isOpera = userAgent.indexOf("Opera") > -1;
        //判断是否Opera浏览器
        if (isOpera) {
            return "Opera"
        }
        //判断是否Firefox浏览器
        if (userAgent.indexOf("Firefox") > -1) {
            return "Firefox";
        }
        //判断是否Chrome浏览器
        if (userAgent.indexOf("Chrome") > -1) {
            return "Chrome";
        }
        //判断是否Safari浏览器
        if (userAgent.indexOf("Safari") > -1) {
            return "Safari";
        }
        //判断是否IE浏览器
        if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
            return "IE";
        }
    }
</script>